﻿package org.sunxin.ch05.servlet;

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;

import org.sunxin.ch05.util.OutputSessionInfo;

public class GreetServlet extends HttpServlet
{
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
               throws ServletException,IOException
    {
        HttpSession session=req.getSession();
        String user=(String)session.getAttribute("user");
        
        if(null==user)
        {
            resp.sendRedirect(resp.encodeRedirectURL("login"));
        }
        else
        {
            resp.setContentType("text/html;charset=gb2312");
            PrintWriter out=resp.getWriter();
            out.println("<html><head><title>欢迎页面</title></head>");
            out.println("<body>");
            
            OutputSessionInfo.printSessionInfo(out,session);
            
            out.println("<p>");
            out.println("欢迎你，"+user+"<p>");
            out.println("<a href="+resp.encodeURL("login")+">重新登录</a>");
            out.println("<a href="+resp.encodeURL("logout")+">注销</a>");
            out.println("</body></html>");
            out.close();
        }
    }
}